import { HintBtnView } from "../../mapUI/HintBtnView";
import { LayerManager } from "../../../manager/LayerManager";
import { ActiveIconChangeInfo } from "../../../model/ActiveIconChangeInfo";
import { ObjCreate } from "../../common/ObjCreate";
import { EffectManager } from "../../../manager/EffectManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { SActiveToClient } from "../../../../../Message/Public/SActiveToClient";
import { Cache } from "../../../cache/Cache";
import { JSONHelper } from "../../../../../com/mui/serialization/json/JSONHelper";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ResManager } from "../../../../common/ResManager";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
//class ActiveBaseIcon
    
    export  class ActiveBaseIcon extends HintBtnView
    {
        constructor(arg1: string=null)
        {
            super();
            this._fileName = arg1;
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            buttonMode = true;
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            layer = LayerManager.rightTopUILayer;
            return;
        }

        public updateIconInfo(arg1: ActiveIconChangeInfo=null): void
        {
            if (arg1 && this._iconInfo == arg1) 
            {
                return;
            }
            this._iconInfo = arg1;
            if (this._iconInfo) 
            {
                this._fileName = this._iconInfo.fileName;
            }
            if (this._loadedBtn && this._loadedBtn.parent == this) 
            {
                this.removeChild(this._loadedBtn);
            }
            this._loadedBtn = ObjCreate.createGLoadedButton(this._fileName, 0, 0, 60, 50, this);
            EffectManager.glowFilterReg(this, [FilterConst.guideTipsFilter], 0.6, 10, 5, 20);
            return;
        }

        protected onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        public updateActiveToClientInfo(arg1: SActiveToClient): void
        {
            var loc5=null;
            var loc1=false;
            if (arg1) 
            {
                loc1 = Cache.instance.active.isActiveInEffect(arg1.code);
            }
            if (arg1 == null || !loc1) 
            {
                if (this._imageBmp && this._imageBmp.parent) 
                {
                    removeChild(this._imageBmp);
                }
                if (this._multipTxt) 
                {
                    this._multipStr = "";
                    this._multipTxt.htmlText = "";
                }
                return;
            }
            var loc2=arg1.modulus;
            var loc3=0;
            var loc4=0;
            if (loc2 && !(loc2 == "")) 
            {
                if ((loc5 = JSONHelper.deserialize(loc2)) && loc5.hasOwnProperty("min")) 
                {
                    loc4 = loc5["min"];
                }
                if (loc5 && loc5.hasOwnProperty("max")) 
                {
                    loc3 = loc5["max"];
                }
            }
            if (loc4 > 0 || loc3 > 0) 
            {
                if (this._imageBmp == null) 
                {
                    this._imageBmp = new GImageBitmap(ImagesConst.ActiveMultipleBg, 25, 3);
                }
                addChild(this._imageBmp);
                if (this._multipTxt == null) 
                {
                    this._tf = new GTextFormat(FontUtil.EmbedNumberName, 14, 16776960, null, null, null, null, null, flash.text.TextFieldAutoSize.RIGHT);
                    this._multipTxt = ObjCreate.createGTextField("", 20, 0, 40, 20, this, this._tf);
                    this._multipTxt.embedFonts = true;
                }
                addChild(this._multipTxt);
                this._multipStr = "×" + loc4;
                if (loc3 > loc4) 
                {
                    this._multipStr = this._multipStr + "-" + loc3;
                }
                this._multipTxt.htmlText = this._multipStr;
                ResManager.instance.registerNumber(this.resetMultipTxt);
            }
            else 
            {
                if (this._imageBmp && this._imageBmp.parent) 
                {
                    removeChild(this._imageBmp);
                }
                if (this._multipTxt) 
                {
                    this._multipStr = "";
                    this._multipTxt.htmlText = "";
                }
            }
            return;
        }

        /* internal  */resetMultipTxt(): void
        {
            if (this._multipTxt) 
            {
                this._multipTxt.setTextFormat(this._tf);
                this._multipTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
                this._multipTxt.htmlText = this._multipStr;
            }
            return;
        }

        protected /* var */_loadedBtn: GLoadedButton;

        protected /* var */_fileName: string;

        protected /* var */_iconInfo: ActiveIconChangeInfo;

        protected /* var */_sActiveToClient: SActiveToClient;

        protected /* var */_imageBmp: GImageBitmap;

        protected /* var */_multipTxt: GTextFiled;

        protected /* var */_multipStr: string="";

        protected /* var */_tf: GTextFormat;
    }
